package ch.zhaw.skuh.turing.model.turingmaschine.rules;

import ch.zhaw.skuh.turing.model.turingmaschine.Subtraction_N_ary;

public class SubtractOneRuleSet extends SubtractionRuleSet {

	public SubtractOneRuleSet(Subtraction_N_ary tc) {
		super(tc);
	}

	// *** override subtraction functions ***
	// bunch of special checks since we subtract only "1"
	// subtraction can thus stop earlier in some cases


	@Override
	// t3 is blank or "1" !!!
	protected void addRulesPart_NoneBlank(int q, int exitCheck0,
			int exitDirect, int[] tapes, String tOld, String tNew) {
		// no overrun to write --> several exits
		if (tNew.substring(2).compareTo("_") == 0) {
			// no overrun: leading 0?
			if (tNew.compareTo("_0_") == 0) {
				// continue searching backwards if result is 0
				tc.addRulePadded(q, tOld, q, tNew, "-1-10", tapes);
			} else {
				// no leading zero
				tc.addRulePadded(q, tOld, exitDirect, tNew, "110", tapes);
			}
		} else {
			// overrun --> continue
			tc.addRulePadded(q, tOld, q, tNew, "-1-10", tapes);
		}
	}
}
